package com.niiwoo.civet.trade.service.local.newRefund.refundDeal.converter;

import com.niiwoo.civet.account.enums.OrderTypeEnum;
import com.niiwoo.civet.base.enums.OrderRefundTypeEnum;
import com.niiwoo.civet.base.enums.RefundTypeEnum;
import com.niiwoo.civet.trade.enums.ProjectSubStatusEnum;
import com.niiwoo.civet.trade.enums.RefundTradeTypeEnum;
import com.niiwoo.civet.trade.enums.RepayStatusEnum;

/**
 *  还款时需要用到的枚举转换 TODO 增加了代还
 */
public class RefundEnumConverter {

    /**
     * 此处转换为冻结记账 依赖trade_type
     * @param trade_type
     * @return
     */
    public static OrderTypeEnum orderTypeEnumConvert(Byte trade_type){
        if (RefundTradeTypeEnum.ADVANCE.getTradeType().equals(trade_type)
                || RefundTradeTypeEnum.REPLACE.getTradeType().equals(trade_type)) {
            return OrderTypeEnum.GUARANTEE;
        } else if (RefundTradeTypeEnum.REPAYMENT.getTradeType().equals(trade_type)) {
            return OrderTypeEnum.REPAYMENT;
        } else{
            throw new RuntimeException("枚举类型无法转换");
        }
    }

    /**
     *  此处转换为冻结记账 refundType tradeType repaystatus
     * @param refundType
     * @param tradeType
     * @param repayStatus
     * @return
     */
    public static OrderRefundTypeEnum orderRefundTypeEnumConvert(Byte refundType, Byte tradeType, Byte repayStatus){
        if(RefundTradeTypeEnum.ADVANCE.getTradeType().equals(tradeType)){
            return null;
        }else{
            if (RefundTypeEnum.OVERDEPT.getRefundType().equals(refundType)) {// 提前结清
                return OrderRefundTypeEnum.OVERDEPT_REFUND;
            } else if(RefundTypeEnum.IMMEDIATELY.getRefundType().equals(refundType)){
                if(RepayStatusEnum.NORMAL.getCode().equals(repayStatus)){
                    return OrderRefundTypeEnum.NORMAL_REFUND;
                }else if(RepayStatusEnum.OVERDUE.getCode().equals(repayStatus)){
                    return OrderRefundTypeEnum.OVERDUE_REFUND;
                }else if(RepayStatusEnum.BADLOANS.getCode().equals(repayStatus)){
                    return OrderRefundTypeEnum.BADLOAN_REFUND;
                }else{
                    throw new RuntimeException("枚举类型无法转换");
                }
            } else{
                throw new RuntimeException("枚举类型无法转换");
            }
        }
    }

    /**
     *   refundType tradeType repaystatus
     * @param repayStatus
     * @return
     */
    public static ProjectSubStatusEnum projectSubStatusEnumConvertForRepaying( Byte repayStatus){

        if (RepayStatusEnum.NORMAL.getCode().equals(repayStatus)) {
            return ProjectSubStatusEnum.REPAYING_INIT;
        }else if(RepayStatusEnum.OVERDUE.getCode().equals(repayStatus)){
                return ProjectSubStatusEnum.REPAYING_OVERDUE;
        }else if(RepayStatusEnum.BADLOANS.getCode().equals(repayStatus)){
                return ProjectSubStatusEnum.REPAYING_BAD;
        }else {
            throw new IllegalArgumentException("不支持此状态转换");
        }
    }

}
